package com.neusoft.listener;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * @Author: duan
 * @Date: Create in 17:26 2020/10/31
 */
@WebListener
public class WebApplicationContextListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        System.out.println("Servlet创建了");
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        servletContextEvent.getServletContext().setAttribute("app", context);
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        System.out.println("Servlet销毁了");
    }
}
